package edu.gdkm.ssm.dao;

import edu.gdkm.ssm.domain.Member;
import edu.gdkm.ssm.domain.Orders;
import edu.gdkm.ssm.domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 订单信息查询仓储
 */
public interface IOrdersDao {

    /**
     * 查询所有订单信息
     * @return
     */
    @Select("select * from orders")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "orderNum", column = "orderNum"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "orderStatus", column = "orderStatus"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "payType", column = "payType"),
            @Result(property = "orderDesc", column = "orderDesc"),
            @Result(property = "product", column = "productId", javaType = Product.class, one = @One(select = "edu.gdkm.ssm.dao.IProductDao.findById")),
    })
    List<Orders> findAll();


    /**
     * 根据订单id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{ordersId}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "orderNum", column = "orderNum"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "orderStatus", column = "orderStatus"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "payType", column = "payType"),
            @Result(property = "orderDesc", column = "orderDesc"),
            @Result(property = "product", column = "productId", javaType = Product.class, one = @One(select = "edu.gdkm.ssm.dao.IProductDao.findById")),
            @Result(property = "member", column = "memberId", javaType = Member.class,one = @One(select = "edu.gdkm.ssm.dao.IMemberDao.findById")),
            @Result(property = "travellers", column = "id", javaType = java.util.List.class,many = @Many(select = "edu.gdkm.ssm.dao.ITravellerDao.findByOrdersId"))
    })
    Orders findById(String id);
}
